var emplid,year,year_item = '',itemLen;
var myiscroll=null;
/*
var url = location.href.split('?')[1];
if(url!=null){
	var arr = url.split('&');
	for(var i = 0 ; i < arr.length;i++){
		var temp = arr[i];
		var tempArr = temp.split('=');
		var key = tempArr[0];
		if(key == "emplid"){
			emplid=tempArr[1];
		}
		if(key == "year"){
			year=tempArr[1];
		}
		if(key == "year_item"){
			year_item=tempArr[1];
		}
	}
}
*/
emplid=getQueryParam("emplid");
year=getQueryParam("year");
year_item=getQueryParam("year_item");
itemLen=getQueryParam("itemLen");

function query(){
	$("#loadingText").show();
	iscroll();
	 $.ajax({
			type: "post",
			url: mpsurl+"/mobile/salary/getSalaryInfo.do",
			dataType: "json",
			data:{year:year,year_item:year_item},
			success: function (data) {
				if(data.resultCode=="500600"){
					$("#ullist").html('');
					var obj = data.value;
					if(obj.length==0){
						$("#mysalarydetail").hide();
						$("#loadingText").hide();
						$("#norecord").show();
						iscroll();
					}else{
						var yearMonth = obj.yearMonth;
						$("#yearAndMonth").html('');
						$("#yearAndMonth").html(yearMonth.substr(0,4)+"年"+yearMonth.substr(5,2)+"月薪水");
						$("#hyearMonth").attr("value",yearMonth);
		
						// （汇总数据）
						var paic_emp_gpdl_m = obj.paic_emp_gpdl_m;
						// 净收入
						var paic_gprslt_col100 = obj.netIncome;
						// 收入项合计
						var paic_gprslt_col1 = obj.incomeAll;
						// 扣减项合计
						var paic_gprslt_col10 = obj.deductionAll;
						// 文本输入
						var paic_emp_gpdl_m_html = "<ul class=\"row-info-list\"><li class=\"income-total\"><div class=\"info-list-cont\">本月净收入</div><div class=\"info-list-num\">"+paic_gprslt_col100+"</div> </li> </ul>";
						$("#byjsr").html('');
						$("#byjsr").html(paic_emp_gpdl_m_html);
						
						// 个人项
						var paic_gp_ee_msg = obj.paicGpEeMsgList;
						var paic_gp_ee_msg_html = "";
						// 收入项
						var paic_gp_ee_msg_html_E = "";
						// 扣减项
						var paic_gp_ee_msg_html_D = "";
						// 组装的DIV
						var paic_gp_ee_msg_html_div = "";
						var j =0;
						var ei=0;
						var di=0;
						// 个人项 下各内容信息
						for(var i = 0; i < paic_gp_ee_msg.length;i++){
							var paic_er_dd=paic_gp_ee_msg[i].paic_er_dd;
	
							// 收入扣减
							var paic_er_dd =paic_gp_ee_msg[i].paic_er_dd;
							// 项目名称
							var descr =paic_gp_ee_msg[i].descr;
							// 金额
							var paic_gprslt_col153=paic_gp_ee_msg[i].paic_gprslt_col153;
							// 帮助
							var help_str=paic_gp_ee_msg[i].help_str;
							if(paic_er_dd == 'E'){
								ei++;
								if(help_str==""){
									paic_gp_ee_msg_html_E = paic_gp_ee_msg_html_E+"<li><div class=\"row-left-icon\"><i>"+ei+"</i></div><div class=\"info-list-cont\">"+descr+"</div> <div class=\"info-list-num\">"+paic_gprslt_col153+"</div></li>"
								}
								else{
									j++;
									paic_gp_ee_msg_html_E = paic_gp_ee_msg_html_E+"<li id=\"J-ClickAskIcon_"+j+"\" ><div class=\"row-left-icon\"><i>"+ei+"</i></div><div class=\"info-list-cont\">"+descr+"<span class=\"ask-icon\"></span></div> <div class=\"info-list-num\">"+paic_gprslt_col153+"</div></li>"
									paic_gp_ee_msg_html_div =paic_gp_ee_msg_html_div+"<div class=\"g-mask\" id=\"GlobalMask_"+j+"\"><div class=\"g-mask-bg\" id=\"MaskBtnCancel_"+j+"\"></div><div class=\"g-mask-layout\"><article class=\"g-mask-content\"><section class=\"g-mask-cont\"><p>"+help_str+"</p></section></article></div></div>";
								}
							}
							else{
								di++;
								if(help_str==""){
									paic_gp_ee_msg_html_D = paic_gp_ee_msg_html_D+"<li><div class=\"row-left-icon\"><i>"+di+"</i></div><div class=\"info-list-cont\">"+descr+"</div> <div class=\"info-list-num\">"+paic_gprslt_col153+"</div></li>"
								}
								else{
									j++;
									paic_gp_ee_msg_html_D = paic_gp_ee_msg_html_D+"<li id=\"J-ClickAskIcon_"+j+"\" ><div class=\"row-left-icon\"><i>"+di+"</i></div><div class=\"info-list-cont\">"+descr+"<span class=\"ask-icon\"></span></div> <div class=\"info-list-num\">"+paic_gprslt_col153+"</div></li>"
									paic_gp_ee_msg_html_div =paic_gp_ee_msg_html_div+"<div class=\"g-mask\" id=\"GlobalMask_"+j+"\"><div class=\"g-mask-bg\" id=\"MaskBtnCancel_"+j+"\"></div><div class=\"g-mask-layout\"><article class=\"g-mask-content\"><section class=\"g-mask-cont\"><p>"+help_str+"</p></section></article></div></div>";
								}
							}
						}
		
						paic_gp_ee_msg_html = paic_gp_ee_msg_html_E+" <li class=\"income-total row-bg-f7fbff\"><div class=\"info-list-cont\">收入项合计</div><div class=\"info-list-num\">"+paic_gprslt_col1+"</div></li>"+paic_gp_ee_msg_html_D
						paic_gp_ee_msg_html = paic_gp_ee_msg_html+"<li class=\"income-total row-bg-f7fbff\"><div class=\"info-list-cont\">扣减项合计</div> <div class=\"info-list-num\">"+paic_gprslt_col10+"</div></li>";
						$("#grx").html('');
						$("#grx").html(paic_gp_ee_msg_html);
						$("#showDiv").html('');
						$("#showDiv").append(paic_gp_ee_msg_html_div);
						
						// 公司项
						var paic_gp_cp_msg = obj.paicGpCpMsgList;
						var paic_gp_cp_msg_html = "";
						var gs_html_div="";
						// 公司项 下各内容信息
						for(var i = 0; i < paic_gp_cp_msg.length;i++){
							var paic_er_dd=paic_gp_cp_msg[i].paic_er_dd;
							// 项目名称
							var cp_descr =paic_gp_cp_msg[i].descr;
							// 金额
							var cp_paic_gprslt_col153=paic_gp_cp_msg[i].paic_gprslt_col153;
							
							var gs_help_str = paic_gp_cp_msg[i].help_str;
							if(gs_help_str==""){
								paic_gp_cp_msg_html = paic_gp_cp_msg_html+" <li><div class=\"row-left-icon\"><i>"+(i+1)+"</i></div><div class=\"info-list-cont\">"+cp_descr+"</div><div class=\"info-list-num\">"+cp_paic_gprslt_col153+"</div> </li>";
							}else{
								j++;
								paic_gp_cp_msg_html = paic_gp_cp_msg_html+"<li id=\"J-ClickAskIcon_"+j+"\" ><div class=\"row-left-icon\"><i>"+(i+1)+"</i></div><div class=\"info-list-cont\">"+cp_descr+"<span class=\"ask-icon\"></span></div> <div class=\"info-list-num\">"+cp_paic_gprslt_col153+"</div></li>"
								//paic_gp_cp_msg_html = paic_gp_cp_msg_html+" <li><div class=\"row-left-icon\"><i>"+(i+1)+"</i></div><div class=\"info-list-cont\">"+cp_descr+"</div><div class=\"info-list-num\">"+cp_paic_gprslt_col153+"</div> </li>"
								gs_html_div =gs_html_div+"<div class=\"g-mask\" id=\"GlobalMask_"+j+"\"><div class=\"g-mask-bg\" id=\"MaskBtnCancel_"+j+"\"></div><div class=\"g-mask-layout\"><article class=\"g-mask-content\"><section class=\"g-mask-cont\"><p>"+gs_help_str+"</p></section></article></div></div>";
							}
						}
						
						$("#gsx").html('');
						$("#gsx").html(paic_gp_cp_msg_html);
						
						$("#showDiv").append(gs_html_div);
						$("#showDiv").children("div").each(function(){
							var id =this.id;
							var gl = "GlobalMask_"+id.split('_')[1];
							var cl = "J-ClickAskIcon_"+id.split('_')[1];
							var cancel = "MaskBtnCancel_"+id.split('_')[1];
							$("#"+cl).on("tap", function(){
								   $("#"+gl).show();
							})
							$("#"+cancel).on("tap", function(){
								$("#"+gl).hide();
							})
							$("#"+gl).on("tap", function(){
								$("#"+gl).hide();
							})
						});
						
						
						// 薪资分配信息
						var paic_gp_br_msg = obj.paicGpBrMsgList;
						var paic_gp_br_msg_html = "";
						// 公司项 下各内容信息
						for(var i = 0; i < paic_gp_br_msg.length;i++){
							var paic_er_dd=paic_gp_br_msg[i].paic_er_dd;
							// 银行名称
							var brank_nm =paic_gp_br_msg[i].depositBank;
							// 账号
							var account_ec_id=paic_gp_br_msg[i].bankCardNum;
							// 百分比
							var percent_rate =paic_gp_br_msg[i].distributPercent;
							// 金额
							var ent_pay_adj=paic_gp_br_msg[i].percentSum;
							
							paic_gp_br_msg_html = paic_gp_br_msg_html+"<li> <div class=\"info-list-cont\"><p>"+account_ec_id +"          "+ brank_nm+"</p><p><span class=\"fn-right\">"+ent_pay_adj+"</span>"+percent_rate+"%</p></div></li>";
						}
						$("#fpmx").html('');
						$("#fpmx").html(paic_gp_br_msg_html);
						$("#mysalarydetail").show();
						$("#loadingText").hide();
						iscroll();
					}
				}else{
					$("#loadingText").hide();
					iscroll();
					var tourl = "/mobile/mysalary/xiangqing.html?year="+year+"&year_item="+year_item;
            		checkLogin(data.resultCode,tourl,data.resultMessage);
				}
			}
		});
 }
$(document).ready(function(){
	$(".top-bar-cont span:first-child").click(function(){  //后退功能
		//history.go(-1);
		//location.href="gzd-chaxun.html?year="+year;
		var param= "year="+year;
		gotoLocation("/mobile/mysalary/gzd-chaxun.html",param);
	});
	$(".top-bar-cont span:last-child").click(function(){  //后退功能
		//location.href="/mobile/index.html";
		gotoLocation("/mobile/index.html","");
	});
	$("#queryThisMonth").on("tap", function(){
		//location.href ='../mywork/qjwork.html?yearMonth='+$("#hyearMonth").val();
		var param= "yearMonth="+$("#hyearMonth").val();
		gotoLocation("/mobile/mywork/qjwork.html",param);
	})
	$("#content").bind("swipeLeft",function(){
		year_item = parseInt(year_item)+1;
		if(year_item<itemLen){
			query();
		}else{
			year_item --;
		}
	});
	$("#content").bind("swipeRight",function(){
		year_item = parseInt(year_item)-1;
		if(year_item<0){
			year_item=0;
		}else{
			query();
		}
	});
	$("#errorBtncancel").on("tap",function(){
		$("#errorMask").hide();
	});
	query();
	$("#toMyfund").on("tap",function(){
		gotoLocation("/mobile/myfund/mszq.html","");
	});
});
function iscroll(){
	var wh = $(window).height()-90-124; 
	if(myiscroll instanceof iScroll)
		myiscroll.destroy();
	$("#contentstr").css("height",wh+"px");
	myiscroll = new iScroll("contentstr",{bounce:false});
}